﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using DG.Tweening;
public class Level3X3HeartLineItem : MonoBehaviour
{
    public int rotIndex;    // 0,1,2,3, 分别代表0,90,180,270度
    public Image bgImage;
    private Color imageColor;
    private float rotTime = 0.0f;
    // Start is called before the first frame update
    void Start()
    {
        imageColor = bgImage.color;
    }

    public void AddRot()
    {
        rotIndex++;
        if (rotIndex > 3)
            rotIndex = 0;
        SetRot(rotIndex);
    }

    public void SetRot(int index)
    {
        ColorShake();
        rotIndex = index;
        switch (rotIndex)
        {
            case 0:
                bgImage.transform.DORotate(Vector3.zero, rotTime);
                break;
            case 1:
                bgImage.transform.DORotate(new Vector3(0, 0, 90), rotTime);
                break;
            case 2:
                bgImage.transform.DORotate(new Vector3(0, 0, 180), rotTime);
                break;
            case 3:
                bgImage.transform.DORotate(new Vector3(0, 0, 270), rotTime);
                break;
            default:
                break;
        }

    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            ColorShake();
        }
    }

    public void ColorShake()
    {
        bgImage.DOColor(Color.white, 0.1f).OnComplete(() =>
        {
            bgImage.DOColor(imageColor, 0.1f);
        });
    }
}
